package com.example.demo.servlet;

import com.example.demo.dao.*;
import com.example.demo.entity.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/test")
public class TestServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //user test
        UserDao userDao = new UserDao();
        UserVo userVo1=new UserVo();
        userVo1.setGender("男");
        userVo1.setPassword("12345");
        userVo1.setTelephone("154986784");
        userVo1.setUserName("小王");
        UserVo userVo2=new UserVo();
        userVo2.setUserID(4);
        userVo2.setGender("女");
        userVo2.setPassword("123445");
        userVo2.setTelephone("154986782");
        userVo2.setUserName("小习");
        //book test
        BookDao bookDao=new BookDao();
        BookVo book1=new BookVo();
        book1.setTitle("假如给我三天光明");
        book1.setAuthor("海伦.凯勒");
        book1.setPrice(30.50);
        book1.setStock(100);
        BookVo book2=new BookVo();
        book2.setTitle("假如给我三天光明");
        book2.setAuthor("海伦.凯勒");
        book2.setPrice(40.50);
        book2.setStock(90);
        book2.setBookid(3);
        CartDao cartDao=new CartDao();
        CartVo cartVo1=new CartVo();
        cartVo1.setBookId(1);
        cartVo1.setUserId(3);
        cartVo1.setQuantity(2);
        CartVo cartVo2=new CartVo();
        cartVo2.setBookId(2);
        cartVo2.setQuantity(2);
        cartVo2.setCartId(5);
//        OrderDetailDao orderDetailDao=new OrderDetailDao();
//        OrderDetailVo orderDetailVo=new OrderDetailVo();
//        orderDetailVo.setOrdersID(5);
//        orderDetailVo.setBookID(2);
//        orderDetailVo.setQuantity(20);
//        orderDetailVo.setUnitPrice(12.50);
//        orderDetailVo.setOrderDetailID(5);
        OrdersDao ordersDao=new OrdersDao();
        OrdersVo ordersVo=new OrdersVo();
        ordersVo.setOrdersid(3);
        ordersVo.setUserid(2);
        ordersVo.setOrdersstatus("已支付");
        ordersVo.setTotalprice(33.33);
        OrderDetailDao orderDetailDao=new OrderDetailDao();


        try {
//          System.out.println(userDao.findByUserId(1));
         // System.out.println(userDao.findUserByName("明"));
            // userDao.updateUser(userVo2);
           // System.out.println(bookDao.findBookId(1));
           // System.out.println(bookDao.findBooks("王"));
           // bookDao.saveBook(book1);
            //bookDao.updateBook(book2);
          //  bookDao.deleteBookByID(3);
           // cartDao.saveCart(cartVo1);
           // cartDao.updateCart(cartVo2);
         //cartDao.deleteCartById(5);
//            System.out.println(orderDetailDao.findByOrderDetailID(1));
//            orderDetailDao.saveOderDetail(orderDetailVo);
//            System.out.println(orderDetailDao.findByOrderDetailID(5));
//            orderDetailDao.updateOrderDetail(orderDetailVo);
//            orderDetailDao.deleteOrderDetail(5);
//            System.out.println(ordersDao.findOrdersId(1));
//            System.out.println(ordersDao.findOrders("已支付"));
//            ordersDao.saveOrders(ordersVo);
//            ordersDao.updateOrder(ordersVo);
//            ordersDao.deleteOrderById(3);
//            System.out.println(bookDao.getBooks());
//            System.out.println(orderDetailDao.getOrderDetail());
//            System.out.println(orderDetailDao.getOrderDetailByUserName("小"));
//            System.out.println(new CartDao().getCartByUserid(1));
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        }
    }
}
